import {
    ADD_CART_COUNT,
    ADD_CART_ITEM,
    RE_CART_CHECKED,
    SUB_CART_COUNT,
    DELETE_CART
} from './mutation_type'

export default {
    [ADD_CART_COUNT](state,payload){
        payload.counter++
    },
    [ADD_CART_ITEM](state,payload){
        payload.counter = 1
        payload.checked = true
        state.cartList.push(payload)
    },
    [RE_CART_CHECKED](state,payload){
        if(payload.TrueAll){
            console.log("sdf")
            state.cartList.map(item=>item.checked = true)
        }else if(payload.FalseAll){
            state.cartList.map(item=>item.checked = false)
        }else if(payload.Index>=0){
            state.cartList[payload.Index].checked = !state.cartList[payload.Index].checked
        }
    },
    [SUB_CART_COUNT](state,payload){
        if(payload.counter>1){
            payload.counter--
        }
    },
    [DELETE_CART](state,payload){
        if(payload.index>=0){
            state.cartList.splice(payload.index,1)
        }
    }
}